<%@ page language="java" pageEncoding="UTF-8"%><%@ include
	file="/WEB-INF/commons/taglibs.jsp"%>
<script type="text/javascript">
function showMsg($item, msgType, msg, timeout){
	var classType='ui-state-highlight';
	if(msgType=='error'){
		classType='ui-state-error';
	}
	$item.addClass(classType);
	$item.html("<span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span>"+msg);
	setTimeout(function(){$item.html('').removeClass(classType);},timeout);
}
function submitFlow(){
	var name=jQuery.trim($('#name').val());
	var content=jQuery.trim($('#content').val());
	var isPublic=$('#isPublic').attr('checked');
	if(name.length==0||content.length==0){
		showMsg($('#message'),'error','请确认电话名称和号码都不能为空',3000);
		return;
	}
	var packId;
	if('${param.packId}'==''){
		packId='0';
	}else{
		packId='${param.packId}';
	}
	$.ajax({
		url: '/ajax/share',
		data: 'name='+name+'&content='+content+'&isPublic='+isPublic+'&packId='+packId,
		type: 'POST',
		timeout: 15000,
		error: function(){showMsg($('#message'),'error','电话提交失败!',3000);},
		success: function(response){
			if(response.search('ERROR')!=-1){
				var msg=response.substring(5);
				showMsg($('#message'),'error','电话分享失败!'+msg,3000);
			}else{
				showMsg($('#message'),'info','电话分享成功!',3000);
				if(packId=='0'){
					setTimeout(function(){window.location.href='/public';},2000);
				}else{
					setTimeout(function(){window.location.href='/home';},2000);
				}
			}
		}
	});
}
$(function(){
	$('#name').focus();
	$('#submitFlow').click(function(){submitFlow();});
	$('#resetFlow').click(function(){$('#name').val('');$('#content').val('');$('#public').attr('checked',true);});
});
</script>

<table>
	<tr>
		<td>
		<div id="left" class="top-border">
		<p class="title">分享电话</p>
		<div id="flowForm">
		<fieldset class="ui-helper-reset"><br />
		<label for="name">名称&nbsp;<input type="text" id="name"
			name="name" value="" class="medium-input ui-widget-content" /></label>&nbsp;<font
			class="smallTips">比如：中国移动</font><br />
		<label for="content">电话&nbsp;<input type="text" id="content"
			name="content" class="large-input ui-widget-content" /></label>&nbsp;<font
			class="smallTips">比如：10086</font><br />
		<input type="checkbox" id="isPublic" name="isPublic" checked><label
			for="isPublic">公开该电话</label></fieldset>
		<div class=btnContainer>
		<button id="submitFlow">提交</button>
		&nbsp;
		<button id="resetFlow">重置</button>
		</div>
		</div>
		</div>
		</td>
		<td>
		<div id="right"></div>
		</td>
	</tr>
</table>
